package com.wenx.restcamel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class AppRest   extends RouteBuilder {
    public static void main(String[] args) throws Exception {

        CamelContext context = new DefaultCamelContext(); // 1. 创建 CamelContext.
        context.addRoutes(new AppRest());
        context.setTracing(true);
        context.start(); // 4. 启动CamelContext.
        Thread.sleep(Integer.MAX_VALUE);  // 为了保持CamelContext处于工作状态，这里需要sleep主线程
        context.stop(); // 最后停止CamelContext
    }

    public void configure() throws Exception {
        restConfiguration()
                .host("localhost")
                .port(8080)
                .apiContextPath("/demo");
        from("quartz://report?cron=10 * * * * ?&stateful=true")
                //.to("rest:get:http://localhost:8080/demo/hello4?id=123&name=abc")
                .to("rest:get:hello4?id=123&name=abc")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("111111111111111111");
                        System.out.println(exchange.getIn().getBody().toString());
                    }
                })
                .log("${body}");
    }
}
